package com.zmn.plat.services.impl.base.faultphenomenon;

import com.zmn.common.utils.date.DateUtil;
import com.zmn.plat.model.entity.base.phenomenon.Phenomenon;
import com.zmn.plat.model.entity.base.phenomenon.PhenomenonQuery;
import com.zmn.plat.model.vo.base.phenomenon.PhenomenonVO;
import com.zmn.plat.persistence.interfaces.base.phenomenon.PhenomenonDao;
import com.zmn.plat.services.interfaces.base.phenomenon.PhenomenonService;
import org.springframework.util.CollectionUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.util.List;
import java.util.Objects;

import com.zmn.common.constant.GlobalConsts;

/**
 * 描述: 故障现象接口实现类
 *
 * @author chengguang
 * @since 2021/11/18 17:54
 */
@Slf4j
@Service
public class PhenomenonServiceImpl implements PhenomenonService {

    private static final String TAG = "故障现象基础服务接口";

    @Resource
    private PhenomenonDao phenomenonDao;

    @Override
    public Phenomenon findById(Integer phenId) {
        if (Objects.isNull(phenId)) {
            log.error("[{}],根据id查询数据phenId为null", TAG);
            return null;
        }
        return phenomenonDao.findById(phenId);
    }

    @Override
    public List<Phenomenon> listByIds(List<Integer> phenIds) {
        if (CollectionUtils.isEmpty(phenIds)) {
            log.error("[{}],按条件查询数据,phenIds为null", TAG);
            return null;
        }
        return phenomenonDao.listByIds(phenIds);
    }

    @Override
    public List<Phenomenon> listByQuery(PhenomenonQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        return phenomenonDao.listByQuery(query);
    }

    @Override
    public List<Phenomenon> listPageByQuery(PhenomenonQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(phenomenonDao.countByQuery(query));
        return phenomenonDao.listPageByQuery(query);
    }

    @Override
    public List<PhenomenonVO> listPagePhenomenonByQuery(PhenomenonQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件查询数据,query为null", TAG);
            return null;
        }
        query.setTotalCount(phenomenonDao.countByQuery(query));
        return phenomenonDao.listPagePhenomenonByQuery(query);
    }

    @Override
    public Integer countByQuery(PhenomenonQuery query) {
        if (Objects.isNull(query)) {
            log.error("[{}],按条件统计数据,query为null", TAG);
            return null;
        }
        return phenomenonDao.countByQuery(query);
    }

    @Override
    public Integer updateByKey(Phenomenon phenomenon) {
        if (Objects.isNull(phenomenon.getPhenId())) {
            log.error("[{}],根据id修改数据,Phenomenon为null", TAG);
            return null;
        }
        return phenomenonDao.updateByKey(phenomenon);
    }

    @Override
    public void updateStatusBatch(List<Integer> ids, Integer status, String operator) {
        if (!Objects.equals(status, GlobalConsts.NO) && !Objects.equals(status, GlobalConsts.YES)) {
            log.error("[{}],status状态超出取值范围", TAG);
            return;
        }
        phenomenonDao.updateStatusBatch(ids, status, operator, DateUtil.getNow());
    }

    @Override
    public Integer insert(Phenomenon phenomenon) {
        if (Objects.isNull(phenomenon)) {
            log.error("[{}],新增数据,Phenomenon为null", TAG);
            return null;
        }
        return phenomenonDao.insert(phenomenon);
    }

    @Override
    public void insertBatch(List<Phenomenon> list) {
        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        phenomenonDao.insertBatch(list);
    }
    @Override
    public void insertBatchById(List<Phenomenon> list) {
        if (CollectionUtils.isEmpty(list)) {
            log.error("[{}],数据为空", TAG);
            return;
        }
        phenomenonDao.insertBatchById(list);
    }

    @Override
    public Integer deleteByKey(Integer phenId) {
        if (Objects.isNull(phenId)) {
            log.error("[{}],根据id删除数据,phenId为null", TAG);
            return null;
        }
        return phenomenonDao.deleteByKey(phenId);
    }

    @Override
    public Integer getMaxSort() {
        return phenomenonDao.getMaxSort();
    }

}